package com.hnu.tockmarket.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import java.util.List;

/**
 * 引导页面适配器
 *
 * @author hnulht
 * @since 2021-07-07
 */
public class GuideAdapter extends PagerAdapter {

    private static final String TAG = "GuideAdapter"; // 日志
    private final List<ImageView> imageViewList; // 图像视图列表

    /**
     * 构造函数
     *
     * @param imageViewList imageViews
     */
    public GuideAdapter(List<ImageView> imageViewList) {
        this.imageViewList = imageViewList;
    }

    /**
     * 获取当前要显示对象的数量
     *
     * @return int
     */
    @Override
    public int getCount() {
        return imageViewList.size();
    }

    /**
     * 判断是否用对象生成界面
     *
     * @param view   view
     * @param object object
     * @return boolean
     */
    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    /**
     * 当前要显示的对象
     *
     * @param container container
     * @param position  position
     * @return Object
     */
    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        container.addView(imageViewList.get(position));
        return imageViewList.get(position);
    }

    /**
     * 从ViewGroup中移除当前对象
     *
     * @param container
     * @param position
     * @param object
     */
    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView(imageViewList.get(position));

    }

}